﻿using Csharp_manytomany_415.Adapters;
using Csharp_manytomany_415.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Csharp_manytomany_415.Controllers
{
    public class HomeController : Controller
    {
        IMovieAdapter _adapter;  //type of interface
        public HomeController() 
        {
        _adapter =  new MovieDataAdapter();  //now type of data adapter
        }
        public ActionResult Index()
        {
            ActorsIndexVm MyVm = new ActorsIndexVm();
            MyVm.Greeting = "Helllooooo";
            MyVm.Movies = _adapter.GetMovies();
            return View(MyVm);
        }

        public ActionResult Create() //rendered Create page
        {
            return View();
        }
        [HttpPost]

        public ActionResult Create(ActorsCreateVm AcM) //accept user content
        {
            _adapter.AddActor(AcM);  //Let adapter save data
            return RedirectToAction("Index"); //redirect index page
        }
       
        
        //MovieDetails
        public ActionResult MovieDetails(int mid)
        {
            // create vm
            MovieDetailsVm dVm = new MovieDetailsVm();
            dVm = _adapter.GetMovieActors(mid);


            return View(dVm);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}